<?php
session_start();

require_once 'LoginController.php';
require_once 'PageView.php';
require_once 'DBConfig.php';
require_once 'Database.php';
require_once 'RegisterController.php';
require_once 'BlogpostsController.php';
require_once 'EditBlogpostController.php';require_once 'NavigationView.php';
require_once 'BlogcommentsController.php';
require_once 'BlogpostsHandler.php';
require_once 'BlogpostreadController.php';


class MasterController{	
	
	public static function DoControll(){
				
		$db = new Database();
		$navigationView = new NavigationView();
		$loginHandler = new LoginHandler($db);
		$pageView = new PageView();
		$pageView->StyleSheet("style.css");
		
		
		$db->Connect(new DBConfig);
		
		//När hemsidan öppnas (startsidan) visas detta.
		$loginController = new LoginController();
		$blogpostreadController = new BlogpostreadController();
		$controller = $loginController->DoControll($db);
		$controller .= $blogpostreadController->DoControll($db);
		
		
		//Om användaren trycker på registerar länken för att registrera sig visas detta.
		if($navigationView->navRegister()){
			$loginController = new LoginController();
			$registerController = new RegisterController();
			$controller = $loginController->DoControll($db);
			$controller .= $registerController->DoControll($db);
		}
		//Om användaren trycker på kommenteralänken visas kommentarer.
		if($navigationView->navComment()){
			$loginController = new LoginController();
			$blogcommentsController = new BlogcommentsController();
			$controller = $loginController->DoControll($db);
			$controller .= $blogcommentsController->DoControll($db);		
		}
		//Om användaren trycker på adminlänken vissas detta.
		if($navigationView->adminBlogposts()){
			$loginController = new LoginController();
			$blogpostController = new BlogpostsController();
			$controller = $loginController->DoControll($db);
			$controller .= $blogpostController->DoControll($db);
		}
		//Om admin trycker på redigera vissas detta.
		if($navigationView->navEdit()){
			$loginController = new LoginController();
			$editBlogpostController = new EditBlogpostController();
			$controller = $loginController->DoControll($db);
			$controller .= $editBlogpostController->DoControll($db);
		}
				

		$body = $pageView->GetXHTML10StrictPage("HejPeter.se", $controller);			
		
		return $body;
		
		$db->Close();
		
	}

}
echo MasterController::DoControll();


?>
	 
		
		
	






